www.gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\svm\xi2svmlight.m
function xi2svmlight(X,I,fname) % XI2SVMLIGHT converts data set to SVM Light format % xi2svmlight(X,I,fname) % % Input: % X [DxN] N patterns of dimension D. % I [1xN] labels of patterns (1 - first class, 2 - second class) % % Output: % Text file in SVM_Light format. % % Modifications: % 30-apr-2001, V. Franc, created fid = fopen( fname, 'w+'); D=size(X,1); N=size(X,2); txt = zeros(1,2*D); inx1 = 1:2:2*D; txt(inx1) = 1:D; inx2 = 2:2:2*D; for i=1:N, if I(i) == 1, fprintf(fid,'+1 '); elseif I(i) == 2, fprintf(fid,'-1 '); else fprintf(fid,'0 '); end x = X(:,i); txt(inx2) = X(:,i); fprintf( fid, '%d:%f ', txt ); fprintf(fid,'\n'); end fclose(fid); return;